package com.xj;

import com.xj.bean.Yellow;
import com.xj.config.MainConfigOfProfile;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * @author: xujiang
 * @createTime: 2021/2/11 14:58
 */

public class IOCTest_Profile {
    @Test
    public void test01() {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
        // 通过代码的方式激活环境
        applicationContext.getEnvironment().setActiveProfiles("test");
        applicationContext.register(MainConfigOfProfile.class);
        applicationContext.refresh();
        String[] names = applicationContext.getBeanNamesForType(Yellow.class);
        for (String name : names) {
            System.out.println(name);
        }
    }
}
